<?php
class Request
{
	public function test_get ($tring)
	{
		$value = $tring;
		$value = htmlspecialchars(stripslashes($value));//chuyen ky tu dac biet
        $value = str_ireplace("script", "", $value);//chuyen nhung lenh nguy hiem
        //$value = mysql_escape_string($value);	
		return $value;
	}
	public function get_string ( $name, $method, $default = NULL )
	{
		$value = $name;
		
		switch($method){
			case 'post':
				if (array_key_exists($value,$_POST)){    		
					$value = $this->test_get($_POST[$value]);
				}
				else
				$value = $default;
			break;
			case 'get':
				if (array_key_exists($value,$_GET)){    		
					$value = $this->test_get($_GET[$value]);
				}
				else
				$value = $default;
			break;
		}
		
		return $value;
	}
	public function checkMai ($mail){
		return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $email);
	}
	public function checkURL($url)
	{
		return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
	}
	public function chuyenLinkURL($url,$url2)//chuyen link neu link do la duong dan tuong doi
	{
		if( !preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url) )
			return $url2.$url;
		else
			return $url2;	
	} 
}
?>